<template>
  <div class="header">
    <div class="logo-wrapper">
      <img src="@/assets/logo.png" alt="">
    </div>
    <div class="user-info">
      你好<span>{{userInfo.name}}</span>
      <a href="#" @click="changeUser">切换用户</a>
    </div>
  </div>
</template>

<script setup>
import store from '@/store';
import { useUserStore } from '@/store/user';
import { storeToRefs } from 'pinia';

const userStore=useUserStore()
const {userInfo}=storeToRefs(userStore)  //仅仅是代理出来的一个副本

 
const changeUser=()=>{
  // 修改'@/store/user'这个仓库的数据
  //1. userInfo.name='老付'  不能用解构出来的数据去改
  // userStore.userInfo.name='老付'
  // console.log(userStore.userInfo.name);

  // 2
  userStore.changeUserInfo('老付')
}




</script>

<style  scoped>
.header{
  display: flex;
  height: 60px;
  background-color: olivedrab;
  padding: 0 10%;
  align-items: center;
  font-size: 24px;
  justify-content: space-between;
}
.logo-wrapper{
  width: 70px;
  height: 70px;

}

.logo-wrapper img{
  width: 100%;

}
a{
  text-decoration: none;
  margin-left: 30px;
}
</style>